home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / tex / files / !tex / TeXsource / commontex / c / dvi < prev    next >
Encoding:
Text File  |  1988-04-18  |  30.6 KB  |  811 lines

  1. /*
  2.  *    Copyright 1986, 1987 Pat Joseph Monardo. All rights reserved.
  3.  *    Copying of this file is granted according to the provisions 
  4.  *    specified in the file COPYING which must accompany this file.
  5.  */
  6.  
  7.  
  8. /*
  9.  *              dvi.c
  10.  */
  11.  
  12. #include "tex.h"
  13. #include "texext.h"
  14. #include "heap.h"
  15. #include "str.h"
  16. #include "io.h"
  17. #include "eq.h"
  18. #include "box.h"
  19. #include "scan.h"
  20. #include "tfm.h"
  21. #include "file.h"
  22. #include "pack.h"
  23. #include "print.h"
  24. #include "error.h"
  25. #include "dvi.h"
  26.  
  27. byte_file       dvi_file;
  28.  
  29. ptr             dvi_ptr;
  30. byte    dvi_buf[DVI_BUF_SIZE];
  31. ptr             dvi_limit = DVI_BUF_SIZE;
  32. val             dvi_offset;
  33. val             dvi_gone;
  34.  
  35. qword   c;
  36. qword   f;
  37. ptr             g;
  38. val             lq;
  39. val             lr;
  40. int             cur_s = -1;/*DIFF*/
  41. scal    cur_h;
  42. scal    cur_v;
  43. fnt             dvi_f;
  44. scal    dvi_h;
  45. scal    dvi_v;
  46. scal    max_h;
  47. scal    max_v;
  48. scal    rule_dp;
  49. scal    rule_ht;
  50. scal    rule_wd;
  51. int             max_push;
  52. int             total_pages;
  53. int             dead_cycles;
  54. bool    doing_leaders;
  55. val             last_bop = -1;
  56.  
  57. ptr             down_ptr;
  58. ptr             right_ptr;
  59.  
  60. dvi_swap ()
  61. {
  62.         if (dvi_limit == DVI_BUF_SIZE) {
  63.                 write_dvi(0, HALF_BUF);
  64.                 dvi_limit = HALF_BUF;
  65.                 dvi_offset += DVI_BUF_SIZE;
  66.                 dvi_ptr = 0;
  67.         } else {
  68.                 write_dvi(HALF_BUF, DVI_BUF_SIZE);
  69.                 dvi_limit = DVI_BUF_SIZE;
  70.         }
  71.         dvi_gone += HALF_BUF;
  72. }
  73.  
  74. dvi_four (x)
  75.         val             x;
  76. {
  77.         if (x >= 0) {
  78.                 dvi_out(x / 0100000000);
  79.         } else {
  80.                 x += 010000000000;
  81.                 x += 010000000000;
  82.                 dvi_out(x / 0100000000 + 128);
  83.         }
  84.         x %= 01000000000;
  85.         dvi_out(x / 0200000);
  86.         x %= 0200000;
  87.         dvi_out(x / 0400);
  88.         dvi_out(x % 0400);
  89. }
  90.  
  91. dvi_pop (l)
  92.         val             l;
  93. {
  94.         if (l == dvi_offset + dvi_ptr && dvi_ptr > 0)
  95.                 decr(dvi_ptr);
  96.         else dvi_out(POP);
  97. }
  98.  
  99. dvi_font_def (f)
  100.         fnt             f;
  101. {
  102.         int             k;
  103.  
  104.         dvi_out(FNT_DEF1);
  105.         dvi_out(f - FONT_BASE - 1);
  106.         dvi_out(qo(font_check[f].b0));
  107.         dvi_out(qo(font_check[f].b1));
  108.         dvi_out(qo(font_check[f].b2));
  109.         dvi_out(qo(font_check[f].b3));
  110.         dvi_four(font_size[f]);
  111.         dvi_four(font_dsize[f]);
  112.         dvi_out(length(font_area[f]));
  113.         dvi_out(length(font_name[f]));
  114.         for (k = str_start[font_area[f]]; k < str_start[font_area[f] + 1]; incr(k))
  115.                 dvi_out(str_pool[k]);
  116.         for (k = str_start[font_name[f]]; k < str_start[font_name[f] + 1]; incr(k))
  117.                 dvi_out(str_pool[k]);
  118. }
  119.  
  120. #define Y_HERE                  1
  121. #define Z_HERE                  2
  122. #define YZ_OK                   3
  123. #define Y_OK                    4
  124. #define Z_OK                    5
  125. #define D_FIXED                 6
  126. #define NONE_SEEN               0
  127. #define Y_SEEN                  6
  128. #define Z_SEEN                  12
  129.  
  130. movement (w, o)
  131.         scal    w;
  132.         byte    o;
  133. {
  134.         val             k;
  135.         ptr             p;
  136.         ptr             q;
  137.         int             mstate;
  138.  
  139.         q = get_node(MOVEMENT_NODE_SIZE);
  140.         width(q) = w;
  141.         location(q) = dvi_offset + dvi_ptr;
  142.         if (o == DOWN1) {
  143.                 link(q) = down_ptr;
  144.                 down_ptr = q;
  145.         } else {
  146.                 link(q) = right_ptr;
  147.                 right_ptr = q;
  148.         }
  149.         mstate = NONE_SEEN;
  150.         for (p = link(q); p != NULL; p = link(p)) {
  151.                 if (width(p) == w) {
  152.                         switch (mstate + info(p))
  153.                         {
  154.                         case NONE_SEEN + YZ_OK:
  155.                         case NONE_SEEN + Y_OK:
  156.                         case Z_SEEN + YZ_OK:
  157.                         case Z_SEEN + Y_OK:
  158.                                 if (location(p) < dvi_gone)
  159.                                         goto not_found;
  160.                                 else {
  161.                                         k = location(p) - dvi_offset;
  162.                                         if (k < 0)
  163.                                                 k += DVI_BUF_SIZE;
  164.                                         dvi_buf[(int)k] += Y1 - DOWN1;
  165.                                         info(p) = Y_HERE;
  166.                                         goto found;
  167.                                 }
  168.                                 break;
  169.                         
  170.                         case NONE_SEEN + Z_OK:
  171.                         case Y_SEEN + YZ_OK:
  172.                         case Y_SEEN + Z_OK:
  173.                                 if (location(p) < dvi_gone) {
  174.                                         goto not_found;
  175.                                 } else {
  176.                                         k = location(p) - dvi_offset;
  177.                                         if (k < 0)
  178.                                                 k += DVI_BUF_SIZE;
  179.                                         dvi_buf[(int)k] += Z1 - DOWN1;
  180.                                         info(p) = Z_HERE;
  181.                                         goto found;
  182.                                 }
  183.                                 break;
  184.                         
  185.                         case NONE_SEEN + Y_HERE:
  186.                         case NONE_SEEN + Z_HERE:
  187.                         case Y_SEEN + Z_HERE:
  188.                         case Z_SEEN + Y_HERE:
  189.                                 goto found;
  190.                                 break;
  191.                         }
  192.                 } else {
  193.                         switch (mstate + info(p))
  194.                         {
  195.                         case NONE_SEEN + Y_HERE:
  196.                                 mstate = Y_SEEN;
  197.                                 break;
  198.                         
  199.                         case NONE_SEEN + Z_HERE:
  200.                                 mstate = Z_SEEN;
  201.                                 break;
  202.                         
  203.                         case Y_SEEN + Z_HERE:
  204.                         case Z_SEEN + Y_HERE:
  205.                                 goto not_found;
  206.                                 break;
  207.                         
  208.                         default:
  209.                                 break;
  210.                         }
  211.                 }
  212.         }
  213.  
  214. not_found:
  215.         info(q) = YZ_OK;
  216.         if (abs(w) >= 040000000) {
  217.                 dvi_out(o + 3);
  218.                 dvi_four(w);
  219.                 return;
  220.         }
  221.         if (abs(w) >= 0100000) {
  222.                 dvi_out(o + 2);
  223.                 if (w < 0)
  224.                         w += 0100000000;
  225.                 dvi_out(w / 0200000);
  226.                 w %= 0200000;
  227.                 goto two;
  228.         }
  229.         if (abs(w) >= 0200) {
  230.                 dvi_out(o + 1);
  231.                 if (w < 0)
  232.                         w += 0200000;
  233.                 goto two;
  234.         }
  235.         dvi_out(o);
  236.         if (w < 0)
  237.                 w += 0400;
  238.         goto one;
  239.  
  240. two: dvi_out(w / 0400);
  241. one: dvi_out(w % 0400);
  242.         return;
  243.  
  244. found:
  245.         info(q) = info(p);
  246.         if (info(q) == Y_HERE) {
  247.                 dvi_out(o + Y0 - DOWN1);
  248.                 while (link(q) != p) {
  249.                         q = link(q);
  250.                         switch (info(q))
  251.                         {
  252.                         case YZ_OK:
  253.                                 info(q) = Z_OK;
  254.                                 break;
  255.                         
  256.                         case Y_OK:
  257.                                 info(q) = D_FIXED;
  258.                                 break;
  259.                         }
  260.                 }
  261.         } else {
  262.                 dvi_out(o + Z0 - DOWN1);
  263.                 while (link(q) != p) {
  264.                         q = link(q);
  265.                         switch (info(q))
  266.                         {
  267.                         case YZ_OK:
  268.                                 info(q) = Y_OK;
  269.                                 break;
  270.                         
  271.                         case Z_OK:
  272.                                 info(q) = D_FIXED;
  273.                                 break;
  274.                         default:
  275.                                 break;
  276.                         }
  277.                 }
  278.         }
  279. }
  280.  
  281. prune_movements (l)
  282.         val             l;
  283. {
  284.         ptr             p;
  285.  
  286.         while (down_ptr != NULL) {
  287.                 if (location(down_ptr) < l)
  288.                         break;
  289.                 p = down_ptr;
  290.                 down_ptr = link(p);
  291.                 free_node(p, MOVEMENT_NODE_SIZE);
  292.         }
  293.         while (right_ptr != NULL) {
  294.                 if (location(right_ptr) < l)
  295.                         break;
  296.                 p = right_ptr;
  297.                 right_ptr = link(p);
  298.                 free_node(p, MOVEMENT_NODE_SIZE);
  299.         }
  300. }
  301.  
  302. hlist_out ()
  303. {
  304.         ptr             p;
  305.         scal    lx;
  306.         scal    edge;
  307.         int             g_sign;
  308.         scal    save_h;
  309.         scal    save_v;
  310.         gord    g_order;
  311.         val             save_loc;
  312.         ptr             this_box;
  313.         scal    base_line;
  314.         scal    leader_wd;
  315.         scal    left_edge;
  316.         ptr             leader_box;
  317.         bool    outer_doing_leaders;
  318.  
  319.         this_box = temp_ptr;
  320.         g_order = glue_order(this_box);
  321.         g_sign = glue_sign(this_box);
  322.         p = list_ptr(this_box);
  323.         incr(cur_s);
  324.         if (cur_s > 0)
  325.                 dvi_out(PUSH);
  326.         if (cur_s > max_push)
  327.                 max_push = cur_s;
  328.         save_loc = dvi_offset + dvi_ptr;
  329.         base_line = cur_v;
  330.         left_edge = cur_h;
  331.         while (p != NULL) {
  332. reswitch:
  333.                 if (is_char_node(p)) {
  334.                         synch_h();
  335.                         synch_v();
  336.                         do {
  337.                                 f = font(p);
  338.                                 c = character(p);
  339.                                 if (f != dvi_f) {
  340.                                         if (!font_used[f]) {
  341.                                                 dvi_font_def(f);
  342.                                                 font_used[f] = TRUE;
  343.                                         }
  344.                                         if (f <= 64 + FONT_BASE) {
  345.                                                 dvi_out(f - FONT_BASE - 1 + FNT_NUM_0);
  346.                                         } else {
  347.                                                 dvi_out(FNT1);
  348.                                                 dvi_out(f - FONT_BASE - 1);
  349.                                         }
  350.                                         dvi_f = f;
  351.                                 }
  352.                                 if (c >= qi(128))/*DIFF*/
  353.                                         dvi_out(SET1);/*DIFF*/
  354.                                 dvi_out(qo(c));/*DIFF*/
  355.                                 cur_h += char_width(f, char_info(f, c));
  356.                                 p = link(p);
  357.                         } while (is_char_node(p));
  358.                         dvi_h = cur_h;
  359.                 } else {
  360.                         switch (type(p))
  361.                         {
  362.                         case HLIST_NODE:
  363.                         case VLIST_NODE:
  364.                                 if (list_ptr(p) == NULL)
  365.                                         cur_h += width(p);
  366.                                 else {
  367.                                         save_h = dvi_h;
  368.                                         save_v = dvi_v;
  369.                                         cur_v = base_line + shift_amount(p);
  370.                                         temp_ptr = p;
  371.                                         edge = cur_h;
  372.                                         if (type(p) == VLIST_NODE)
  373.                                                 vlist_out();
  374.                                         else hlist_out();
  375.                                         dvi_h = save_h;
  376.                                         dvi_v = save_v;
  377.                                         cur_h = edge + width(p);
  378.                                         cur_v = base_line;
  379.                                 }
  380.                                 break;
  381.                         
  382.                         case RULE_NODE:
  383.                                 rule_ht = height(p);
  384.                                 rule_dp = depth(p);
  385.                                 rule_wd = width(p);
  386.                                 goto fin_rule;
  387.                                 break;
  388.                         
  389.                         case WHATSIT_NODE:
  390.                                 out_whatsit(p);
  391.                                 break;
  392.                         
  393.                         case GLUE_NODE:
  394.                                 g = glue_ptr(p);
  395.                                 rule_wd = width(g);
  396.                                 if (g_sign != NORMAL) {
  397.                                         if (g_sign == STRETCHING) {
  398.                                                 if (stretch_order(g) == g_order)
  399.                                                         rule_wd += round(glue_set(this_box) * stretch(g));
  400.                                         } else {
  401.                                                 if (shrink_order(g) == g_order)
  402.                                                         rule_wd -= round(glue_set(this_box) * shrink(g));
  403.                                         }
  404.                                 }
  405.                                 if (subtype(p) >= A_LEADERS) {
  406.                                         leader_box = leader_ptr(p);
  407.                                         if (type(leader_box) == RULE_NODE) {
  408.                                                 rule_ht = height(leader_box);
  409.                                                 rule_dp = depth(leader_box);
  410.                                                 goto fin_rule;
  411.                                         }
  412.                                         leader_wd = width(leader_box);
  413.                                         if (leader_wd > 0 && rule_wd > 0) {
  414.                                                 rule_wd += 10;/*DIFF*/
  415.                                                 edge = cur_h + rule_wd;
  416.                                                 lx = 0;
  417.                                                 if (subtype(p) == A_LEADERS) {
  418.                                                         save_h = cur_h;
  419.                                                         cur_h = left_edge +
  420.                                                                 leader_wd * ((cur_h - left_edge) / leader_wd);
  421.                                                         if (cur_h < save_h)
  422.                                                                 cur_h += leader_wd;
  423.                                                 } else {
  424.                                                         lq = rule_wd / leader_wd;
  425.                                                         lr = rule_wd % leader_wd;
  426.                                                         if (subtype(p) == C_LEADERS)
  427.                                                                 cur_h += (lr / 2);
  428.                                                         else {
  429.                                                                 lx = (2 * lr + lq + 1) / (2 * lq + 2);
  430.                                                                 cur_h += (lr - (lq - 1) * lx) / 2;
  431.                                                         }
  432.                                                 }
  433.                                                 while (cur_h + leader_wd <= edge) {
  434.                                                         cur_v = base_line + shift_amount(leader_box);
  435.                                                         synch_v();
  436.                                                         save_v = dvi_v;
  437.                                                         synch_h();
  438.                                                         save_h = dvi_h;
  439.                                                         temp_ptr = leader_box;
  440.                                                         outer_doing_leaders = doing_leaders;
  441.                                                         doing_leaders = TRUE;
  442.                                                         if (type(leader_box) == VLIST_NODE)
  443.                                                                 vlist_out();
  444.                                                         else hlist_out();
  445.                                                         doing_leaders = outer_doing_leaders;
  446.                                                         dvi_v = save_v;
  447.                                                         dvi_h = save_h;
  448.                                                         cur_v = save_v;
  449.                                                         cur_h = save_h + lx + leader_wd;
  450.                                                 }
  451.                                         }
  452.                                         cur_h = edge - 10;/*DIFF*/
  453.                                         goto next_p;
  454.                                 }
  455.                                 goto move_past;
  456.                                 break;
  457.                         
  458.                         case KERN_NODE:
  459.                         case MATH_NODE:
  460.                                 cur_h += width(p);
  461.                                 break;
  462.                         
  463.                         case LIGATURE_NODE:
  464.                                 make_char_from_lig();
  465.                                 goto reswitch;
  466.  
  467.                         default: break;
  468.                         }
  469.                         goto next_p;
  470.  
  471.                 fin_rule:
  472.                         if (is_running(rule_ht))
  473.                                 rule_ht = height(this_box);
  474.                         if (is_running(rule_dp))
  475.                                 rule_dp = depth(this_box);
  476.                         rule_ht = rule_ht + rule_dp;
  477.                         if (rule_ht > 0 && rule_wd > 0) {
  478.                                 synch_h();
  479.                                 cur_v = base_line + rule_dp;
  480.                                 synch_v();
  481.                                 dvi_out(SET_RULE);
  482.                                 dvi_four(rule_ht);
  483.                                 dvi_four(rule_wd);
  484.                                 cur_v = base_line;
  485.                                 dvi_h += rule_wd;
  486.                         }
  487.  
  488.                 move_past:
  489.                         cur_h += rule_wd;
  490.  
  491.                 next_p:
  492.                         p = link(p);
  493.                 }
  494.         }
  495.         prune_movements(save_loc);
  496.         if (cur_s > 0)
  497.                 dvi_pop(save_loc);
  498.         decr(cur_s);
  499. }
  500.  
  501. vlist_out ()
  502. {
  503.         ptr             p;
  504.         scal    lx;
  505.         scal    edge;
  506.         int             g_sign;
  507.         scal    save_h;
  508.         scal    save_v;
  509.         gord    g_order;
  510.         val             save_loc;
  511.         scal    top_edge;
  512.         ptr             this_box;
  513.         scal    leader_ht;
  514.         scal    left_edge;
  515.         ptr             leader_box;
  516.         bool    outer_doing_leaders;
  517.  
  518.         this_box = temp_ptr;
  519.         g_order = glue_order(this_box);
  520.         g_sign = glue_sign(this_box);
  521.         p = list_ptr(this_box);
  522.         incr(cur_s);
  523.         if (cur_s > 0)
  524.                 dvi_out(PUSH);
  525.         if (cur_s > max_push)
  526.                 max_push = cur_s;
  527.         save_loc = dvi_offset + dvi_ptr;
  528.         left_edge = cur_h;
  529.         cur_v -= height(this_box);
  530.         top_edge = cur_v;
  531.         while (p != NULL) {
  532.                 if (is_char_node(p))
  533.                         confusion("vlistout");
  534.                 else {
  535.                         switch (type(p))
  536.                         {
  537.                         case HLIST_NODE:
  538.                         case VLIST_NODE:
  539.                                 if (list_ptr(p) == NULL)
  540.                                         cur_v += height(p) + depth(p);
  541.                                 else {
  542.                                         cur_v += height(p);
  543.                                         synch_v();
  544.                                         save_h = dvi_h;
  545.                                         save_v = dvi_v;
  546.                                         cur_h = left_edge + shift_amount(p);
  547.                                         temp_ptr = p;
  548.                                         if (type(p) == VLIST_NODE)
  549.                                                 vlist_out();
  550.                                         else hlist_out();
  551.                                         dvi_h = save_h;
  552.                                         dvi_v = save_v;
  553.                                         cur_v = save_v + depth(p);
  554.                                         cur_h = left_edge;
  555.                                 }
  556.                                 break;
  557.                         
  558.                         case RULE_NODE:
  559.                                 rule_ht = height(p);
  560.                                 rule_dp = depth(p);
  561.                                 rule_wd = width(p);
  562.                                 goto fin_rule;
  563.                                 break;
  564.                         
  565.                         case WHATSIT_NODE:
  566.                                 out_whatsit(p);
  567.                                 break;
  568.                         
  569.                         case GLUE_NODE:
  570.                                 g = glue_ptr(p);
  571.                                 rule_ht = width(g);
  572.                                 if (g_sign != NORMAL) {
  573.                                         if (g_sign == STRETCHING) {
  574.                                                 if (stretch_order(g) == g_order)
  575.                                                         rule_ht += round(glue_set(this_box) * stretch(g));
  576.                                         } else if (shrink_order(g) == g_order)
  577.                                                         rule_ht -= round(glue_set(this_box) * shrink(g));
  578.                                 }
  579.                                 if (subtype(p) >= A_LEADERS) {
  580.                                         leader_box = leader_ptr(p);
  581.                                         if (type(leader_box) == RULE_NODE) {
  582.                                                 rule_wd = width(leader_box);
  583.                                                 rule_dp = 0;
  584.                                                 goto fin_rule;
  585.                                         }
  586.                                         leader_ht = height(leader_box) + depth(leader_box);
  587.                                         if (leader_ht > 0 && rule_ht > 0) {
  588.                                                 rule_ht += 10;/*DIFF*/
  589.                                                 edge = cur_v + rule_ht;
  590.                                                 lx = 0;
  591.                                                 if (subtype(p) == A_LEADERS) {
  592.                                                         save_v = cur_v;
  593.                                                         cur_v = top_edge +
  594.                                                                 leader_ht * ((cur_v - top_edge) / leader_ht);
  595.                                                         if (cur_v < save_v)
  596.                                                                 cur_v += leader_ht;
  597.                                                 } else {
  598.                                                         lq = rule_ht / leader_ht;
  599.                                                         lr = rule_ht % leader_ht;
  600.                                                         if (subtype(p) == C_LEADERS)
  601.                                                                 cur_v += lr / 2;
  602.                                                         else {
  603.                                                                 lx = (2 * lr + lq + 1) / (2 * lq + 2);
  604.                                                                 cur_v += (lr - (lq - 1) * lx) / 2;
  605.                                                         }
  606.                                                 }
  607.                                                 while (cur_v + leader_ht <= edge) {
  608.                                                         cur_h = left_edge + shift_amount(leader_box);
  609.                                                         synch_h();
  610.                                                         save_h = dvi_h;
  611.                                                         cur_v += height(leader_box);
  612.                                                         synch_v();
  613.                                                         save_v = dvi_v;
  614.                                                         temp_ptr = leader_box;
  615.                                                         outer_doing_leaders = doing_leaders;
  616.                                                         doing_leaders = TRUE;
  617.                                                         if (type(leader_box) == VLIST_NODE) 
  618.                                                                 vlist_out();
  619.                                                         else hlist_out();
  620.                                                         doing_leaders = outer_doing_leaders;
  621.                                                         dvi_v = save_v;
  622.                                                         dvi_h = save_h;
  623.                                                         cur_h = save_h;
  624.                                                         cur_v = save_v - height(leader_box)+lx+leader_ht;
  625.                                                 }
  626.                                                 cur_v = edge - 10;/*DIFF*/
  627.                                                 goto next_p;
  628.                                         }
  629.                                 }
  630.                                 goto move_past;
  631.                                 break;
  632.                         
  633.                         case KERN_NODE:
  634.                                 cur_v += width(p);
  635.                                 break;
  636.  
  637.                         default:
  638.                                 break;
  639.                         }
  640.                         goto next_p;
  641.  
  642.                 fin_rule:
  643.                         if (is_running(rule_wd))
  644.                                 rule_wd = width(this_box);
  645.                         rule_ht += rule_dp;
  646.                         cur_v += rule_ht;
  647.                         if (rule_ht > 0 && rule_wd > 0) {
  648.                                 synch_h();
  649.                                 synch_v();
  650.                                 dvi_out(PUT_RULE);
  651.                                 dvi_four(rule_ht);
  652.                                 dvi_four(rule_wd);
  653.                         }
  654.                         goto next_p;
  655.  
  656.                 move_past:
  657.                         cur_v += rule_ht;
  658.                 }
  659.  
  660.         next_p:
  661.                 p = link(p);
  662.         }
  663.         prune_movements(save_loc);
  664.         if (cur_s > 0)
  665.                 dvi_pop(save_loc);
  666.         decr(cur_s);
  667. }
  668.  
  669. #define ensure_dvi_open() \
  670.         {if (dvi_name == 0) { \
  671.                 if (job_name == 0) \
  672.                         job_name = str_texput; \
  673.                 pack_job_name(str_dvi); \
  674.                 while ((dvi_file = b_open_out()) == NULL) \
  675.                         prompt_file_name("file name for output", str_dvi); \
  676.                 dvi_name = b_make_name_string(dvi_file);}}
  677.  
  678. ship_out (p)
  679.         ptr             p;
  680. {
  681.         int             j;
  682.         int             k;
  683.         int             s;
  684.         val             page_loc;
  685.  
  686.         if (tracing_output > 0) {
  687.                 print_ln();
  688.                 print_nl("Completed box being shipped out");
  689.         }
  690.         if (term_offset > MAX_PRINT_LINE - 9)
  691.                 print_ln();
  692.         else if (term_offset > 0 || file_offset > 0)
  693.                 print_char(' ');
  694.         print_char('['); 
  695.         for (j = 9; count(j) == 0 && j > 0; decr(j))
  696.                 {}
  697.         for (k = 0; k <= j; incr(k)) {
  698.                 print_val(count(k));
  699.                 if (k < j)
  700.                         print_char('.');
  701.         }
  702.         update_terminal();
  703.         if (tracing_output > 0) {
  704.                 print_char(']');
  705.                 begin_diagnostic();
  706.                 show_box(p);
  707.                 end_diagnostic(TRUE);
  708.         }
  709.         if (height(p) > MAX_DIMEN || depth(p) > MAX_DIMEN ||
  710.                 height(p) + depth(p) + v_offset > MAX_DIMEN ||
  711.                 width(p) + h_offset > MAX_DIMEN) {
  712.                 print_err("Huge page cannot be shipped out");
  713.                 help_huge_page();
  714.                 error();
  715.                 if (tracing_output <= 0) {
  716.                         begin_diagnostic();
  717.                         print_nl("The following box has been deleted:");
  718.                         show_box(p);
  719.                         end_diagnostic(TRUE);
  720.                 }
  721.                 goto done;
  722.         }
  723.         if (height(p) + depth(p) + v_offset > max_v)
  724.                 max_v = height(p) + depth(p) + v_offset;
  725.         if (width(p) + h_offset > max_h)
  726.                 max_h = width(p) + h_offset;
  727.         dvi_h = 0;
  728.         dvi_v = 0;
  729.         cur_h = h_offset;
  730.         dvi_f = NULL_FONT;
  731.         /*DIFF cur_s = -1;*/
  732.         ensure_dvi_open();
  733.         if (total_pages == 0) {
  734.                 dvi_out(PRE);
  735.                 dvi_out(ID_BYTE); 
  736.                 dvi_four(25400000);
  737.                 dvi_four(473628672);
  738.                 prepare_mag();
  739.                 dvi_four(mag); 
  740.                 old_setting = selector;
  741.                 selector = NEW_STRING;
  742.                 print("Common TeX output "); 
  743.                 print_int(year);
  744.                 print_char('.');
  745.                 print_two(month);
  746.                 print_char('.');
  747.                 print_two(day);
  748.                 print_char(':');
  749.                 print_two(time / 60);
  750.                 print_two(time % 60);
  751.                 selector = old_setting;
  752.                 dvi_out(cur_length());
  753.                 for (s = str_start[str_ptr]; s < pool_ptr; incr(s))
  754.                         dvi_out(str_pool[s]);
  755.                 pool_ptr = str_start[str_ptr];
  756.         }
  757.         page_loc = dvi_offset + dvi_ptr;
  758.         dvi_out(BOP);
  759.         for (k = 0; k <= 9; incr(k))
  760.                 dvi_four(count(k));
  761.         dvi_four(last_bop);
  762.         last_bop = page_loc;
  763.         cur_v = height(p) + v_offset;
  764.         temp_ptr = p;
  765.         if (type(p) == VLIST_NODE) 
  766.                 vlist_out();
  767.         else hlist_out();
  768.         dvi_out(EOP);
  769.         incr(total_pages);
  770.         cur_s = -1;
  771.  
  772. done:
  773.         if (tracing_output <= 0) print_char(']'); 
  774.         dead_cycles = 0;
  775.         update_terminal();
  776.  
  777. #ifdef STAT
  778.         if (tracing_stats > 1) {
  779.                 print_nl("Memory usage before: ");
  780.                 print_int(var_used);
  781.                 print_char('&');
  782.                 print_int(dyn_used);
  783.                 print_char(';');
  784.         }
  785. #endif
  786.  
  787.         flush_node_list(p);
  788.  
  789. #ifdef STAT
  790.         if (tracing_stats > 1) {
  791.                 print(" after: ");
  792.                 print_int(var_used);
  793.                 print_char('&');
  794.                 print_int(dyn_used);
  795.                 print("; still untouched: ");
  796.                 print_int(hi_mem_min - lo_mem_max - 1);
  797.                 print_ln();
  798.         }
  799. #endif
  800. }
  801.  
  802. /*
  803.  *      Help text
  804.  */
  805.  
  806. help_huge_page ()
  807. {
  808.         help2("The page just created is more than 18 feet tall or",
  809.         "more than 18 feet wide, so I suspect something went wrong.");
  810. }
  811.